﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FaceSharp.Api.GraphApi
{
    public class TypedGraphClient<T> : GenericGraphClient
    {
        private readonly Func<string, T> _typedGraphResultConverter;
        public TypedGraphClient(IFacebookCore facebookCore, Func<string, T> typedGraphResultConverter)
            : base(facebookCore)
        {
            _typedGraphResultConverter = (rawResults) => { return typedGraphResultConverter(rawResults); };
        }

        public T GetMetaData(string id)
        {
            return base.GetMetaData(id, _typedGraphResultConverter).Results;
        }

        public T MakeGraphPost(
         string id,
         Dictionary<string, string> parameters
         )
        {
            return base.MakeGraphPost(id, parameters, _typedGraphResultConverter).Results;
        }

        public T MakeGraphPost(
             string id,
             string connection,
             Dictionary<string, string> parameters
             )
        {
            return base.MakeGraphPost(id,connection,parameters,_typedGraphResultConverter).Results;
        }

        public T MakeGraphSeach(
            string query = null,
            string objectType = null
            )
        {
            return base.MakeGraphSeach(_typedGraphResultConverter, query, objectType).Results;
        }

        public T MakeGraphRequest(
             string id,
             string connection = null,
             IEnumerable<string> fields = null)
        {
            return base.MakeGraphRequest(id, _typedGraphResultConverter, connection, fields).Results;
        }

        public T MakeGraphRequest(
            IEnumerable<string> ids,
            IEnumerable<string> fields = null)
        {
            return base.MakeGraphRequest(ids, _typedGraphResultConverter, fields).Results;
        }
    }
}
